#define _CRT_SECURE_NO_WARNINGS 1

class Solution {
public:
    int countOfPairs(vector<int>& nums) {
        using LL = long long;
        const int MOD = 1e9 + 7;
        int n = nums.size();
        LL dp[2010][55] = { 0 };
        for (int j = 0; j <= nums[0]; j++) dp[0][j] = 1;

        for (int i = 1; i < n; i++)
        {
            for (int j = 0; j <= nums[i]; j++)
            {
                for (int k = 0; k <= j; k++)
                {
                    if (nums[i - 1] - k >= nums[i] - j) dp[i][j] += dp[i - 1][k];
                    dp[i][j] %= MOD;
                }
            }
        }

        LL res = 0;
        for (int j = 0; j <= nums[n - 1]; j++) res += dp[n - 1][j];
        res %= MOD;
        return res;
    }
};